<template>
  <div>
    <el-card>
      <!-- 搜索 -->
      <div class="serach">
        <div class="searchVal">
          <p>违规类型</p>
          <el-select v-model="styleVal" placeholder="不限">
            <el-option label="犯罪" value="1"> </el-option>
            <el-option label="很犯罪" value="2"> </el-option>
          </el-select>
        </div>
        <div class="searchVal">
          <p>时间</p>
          <el-date-picker
            style="margin-right: 20px"
            v-model="TimeVal"
            type="daterange"
            align="right"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="pickerOptions"
            value-format="yyyy-MM-dd"
            @change="focus"
          >
          </el-date-picker>
        </div>
        <el-button>导出Excel</el-button>
      </div>
      <!-- 表格 -->
      <el-table :data="tableData" style="width: 100%" v-loading="loading">
        <el-table-column align="center" prop="name" label="时间">
        </el-table-column>
        <el-table-column align="center" prop="name" label="违规原因">
        </el-table-column>
        <el-table-column align="center" prop="name" label="处理方式">
        </el-table-column>
      </el-table>
      <el-pagination
        style="float: right; margin: 20px"
        :current-page="page"
        :page-size="pageSize"
        :page-sizes="[10, 20, 30, 40]"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      styleVal: "", //违规类型
      TimeVal: "", //时间日期选择
      //   日期时间选择器数组
      pickerOptions: {
        disabledDate(platformValue) {
          return platformValue.getTime() > Date.now() - 8.64e6;
        },
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 6);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      timeStart: "", //开始时间
      timeEnd: "", //结束时间
      loading: false,
      page: 1, //当前页
      pageSize: 10, //当前页条数
      total: 0, //总计
      tableData: [],
    };
  },
  methods: {
    //获取开始/结束时间
    focus(time) {
      if (!this.TimeVal) {
        this.TimeVal = [];
      }
      this.timeStart = this.TimeVal[0];
      this.timeEnd = this.TimeVal[1];
    },

    // 改变条数
    handleSizeChange(val) {
      this.pageSize = val;
    },
    // 改变页数
    handleCurrentChange(val) {
      this.page = val;
    },
  },
};
</script>

<style lang="less" scoped>
.serach {
  display: flex;
  margin-bottom: 30px;
  align-items: center;
  .searchVal {
    display: flex;
    margin-right: 30px;
    p {
      width: 80px;
      text-align: center;
      border: 1px solid #dcdfe6;
      border-right: 0px;
      height: 40px;
      line-height: 20px;
      margin: 0px;
      background: #f5f7fa;
      color: #909399;
      font-size: 14px;
      padding: 10px;
      border-radius: 4px 0px 0px 4px;
    }
  }
  /deep/.el-button {
    margin-left: 30px;
  }
}
</style>